package com.cskaoyan.controller;

import com.cskaoyan.bean.User;
import com.cskaoyan.service.UserService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Map;

@RestController
public class AuthController {

//    AuthService authService;

    @RequestMapping("admin/auth/login")
    public BaseRespVo login(@RequestBody Map map){ //json以javabean或map来接收
        //shiro
        return BaseRespVo.ok("2f510c67-0f31-43b2-91dd-629b19713126");
    }
    /**
     * roles : ["超级管理员"]
     * name : admin123
     * perms : ["*"]
     * avatar : https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif
     */
    @RequestMapping("admin/auth/info")
    public BaseRespVo info(String token){ //json以javabean或map来接收
        //shiro
        Info info = new Info();
        ArrayList<String> roles = new ArrayList<>();
        roles.add("超级管理员");
        info.setRoles(roles);
        ArrayList<String> perms = new ArrayList<>();
        perms.add("*");
        info.setPerms(perms);
        info.setName("超级管理员");
        info.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        return BaseRespVo.ok(info);
    }

    @Autowired
    UserService userService;
    @RequestMapping("user/query/{id}")
    public BaseRespVo queryUser(@PathVariable("id") Integer id) {
        User user = userService.queryById(id);
        return BaseRespVo.ok(user);
    }
}
